home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Help / MacPerl Help < prev    next >
Encoding:
Text File  |  2000-08-23  |  20.7 KB  |  643 lines

  1.  
  2. MacPerl Support in Alpha
  3.  
  4.                                                version: 3.3
  5.                                                created: 07/18/95 {06:15:07 pm} 
  6.                                            last update: 08/23/00 {03:13:34 pm}
  7.  
  8.           Introduction
  9.  
  10.  
  11. This document describes the use of the MacPerl menu in Alpha.  The MacPerl
  12. menu was written to allow Alpha to act as a front end for Matthias
  13. Neeracher's standalone MacPerl application and to make it possible to
  14. "attach" Perl scripts to Alpha.  It provides a number of features designed
  15. to make the use and development of Perl scripts on the Mac more convenient. 
  16. These are detailed in the rest of this document (most easily navigated
  17. using the "M" menu on the sidebar), but here's a quick overview:
  18.  
  19.     Editing Perl scripts...
  20.  
  21. • Perl keywords and special variables are colorized in Perl mode.
  22.  
  23. • The Perl 4 man page is provided as an on-line reference, 
  24.   available as the file "Perl Commands" in Alpha's Help menu; it has 
  25.   been colorized and indexed to make it easy to read and navigate.
  26.  
  27. • The man page can be referenced by command-double-clicking a 
  28.   highlighted Perl keyword or special variable in your Perl script.
  29.   
  30. • Source files mentioned in require statements can be opened by 
  31.   command-double-clicking as well. 
  32.  
  33.     Running Perl Scripts...
  34.  
  35. • MacPerl scripts can be run directly from Alpha - a script can be 
  36.   a text window in Alpha, a highlighted selection from a window, or a 
  37.   disk file.
  38.  
  39. • You can save scripts as MacPerl droplets and runtime applications 
  40.   directly from Alpha.
  41.  
  42. • Perl scripts that read from standard input and write to standard 
  43.   output may be used to process text in Alpha's text windows.
  44.  
  45.     Debugging Perl scripts...
  46.  
  47. • When a script fails, the error messages are displayed and the 
  48.   script is brought up with the line that caused the error highlighted.
  49.  
  50. • A flag can be set to cause scripts to run under the Perl 
  51.   debugger (without modifying the script).
  52.  
  53.  
  54. Currently, no explicit support or documentation is provided for Perl 5, but
  55. this will follow once a stable port of Perl 5 to the 68k Macintosh emerges.
  56.  
  57. Instructions for obtaining the MacPerl application are given further below.
  58.  
  59.  
  60.           Installation
  61.  
  62.  
  63. No special installation procedure is required before using this package. 
  64. However, there are a couple of things that you may need to do to configure
  65. things for your particular machine.
  66.  
  67.  
  68.                MacPerl application and library
  69.  
  70.  
  71. Alpha needs to know where to find your MacPerl application in order to
  72. interact with it, and will automatically prompt you to locate it if it
  73. doesn't know where it is.  You can always check and/or change the path that
  74. Alpha uses by selecting the "MacPerl" preference, available in the menu
  75. item "Config --> Mode Prefs --> Preferences".
  76.  
  77. When opening "require"d source files via the command-double-click
  78. mechanism, Alpha will always look in the "lib" folder in the MacPerl
  79. application directory.  To have Alpha look for library files elsewhere, you
  80. can specify an additional personal library folder, using the "MacPerl lib
  81. folder" preference in "Mode:App Paths" menu.
  82.  
  83.  
  84.                Text Filters Setup
  85.  
  86.  
  87. If you want to use Perl scripts to process Alpha text buffers (see Text
  88. Filters), you'll need to arrange that the Perl menu is visible while you're
  89. in Text mode.  While in Text mode, select "Set Mode Menus…" from the "√"
  90. pop-up menu on the side-bar and command-click on "perlMenu" in the list of
  91. menus shown.  The little camel icon should appear on the menu bar when
  92. you're done.
  93.  
  94. The MacPerl menu contains a hierarchical submenu of preattached scripts to
  95. be used as text filters.  A sample collection of such scripts is
  96. distributed with Alpha in the ":Tcl:UserCode:Text Filters:" folder.  You
  97. can specify your own folder of scripts using "MacPerl Text Filters folder"
  98. entry in "Mode:App Paths" menu.
  99.  
  100.                Option flags
  101.  
  102. There are a handful of flags you can set to modify the way Alpha and 
  103. MacPerl interact while running Perl scripts.  These can be set from 
  104. either the MacPerl menu or the "√" pop-up menu on the side-bar.  They're
  105. described in detail below.
  106.  
  107.  
  108.           Perl Mode
  109.  
  110.  
  111. Perl mode is entered automatically whenever you open a file with a ".pl" or
  112. ".ph" suffix; you can also invoke it explicitly using the modes menu in the
  113. status bar.  A "Perl Example.pl" syntax file is available for exploring 
  114. some of the mode's features and the Perl menu.
  115.  
  116. Perl mode offers a number of features supporting the editting
  117. and debugging of Perl scripts:
  118.  
  119.  
  120.                Basic language support
  121.  
  122.  
  123. • Perl keywords and special variables appear in blue in Perl mode.
  124.  
  125. • A single line or a selected block of lines may be commented out by 
  126.   using the "Comment Line" command under the "Convert" menu.  Lines
  127.   are uncommented using "Uncomment Line", which appears in the "Convert" 
  128.   menu when the option key is held down.
  129.  
  130. • Alpha will create an index of all subroutines in your Perl script when 
  131.   you select "Mark File" from the Marks menu on the sidebar (the "{}" 
  132.   button).  Once created this index is saved with your file.  
  133.  
  134.   When you open a Perl script that hasn't already been indexed, an index 
  135.   is automatically created.
  136.  
  137.  
  138.                Command-double-clicking
  139.  
  140.  
  141. A simple form of hypertext help is invoked by double-clicking on certain
  142. pieces of text while the command key is held down:
  143.  
  144. • The online man page can be referenced by command-double-clicking a 
  145.   highlighted Perl keyword or special variable in your Perl script.
  146.   
  147.   Most of the clickable keywords and variables will be colored blue.
  148.   Special variables containing alphabetic characters, .e.g. @ARGV,
  149.   are also clickable but are not colored. 
  150.   
  151. • Command-double-clicking on the name of the source file in a require
  152.   statement will cause that file to be opened by Alpha.  
  153.  
  154.   Alpha will look for the file in the current script's folder, in your local 
  155.   library folder and in the MacPerl lib folder (in that order).  The local 
  156.   lib folder may be specified interactively by the user (see Installation).
  157.  
  158.  
  159.                Mode Preferences
  160.  
  161.  
  162. A more complete set of Perl option flags are also settable through the menu
  163. item "Config --> Mode Prefs --> Preferences " menu item (while you're in
  164. Perl mode).
  165.  
  166.     perlAutoSwitch         
  167.  
  168. (same as "Auto Switch" under "General Options")
  169.  
  170.     perlGetOutput        
  171.  
  172. (same as "Retrieve Output" under "General Options")
  173.  
  174.     perlOverwrite        
  175.  
  176. (same as "Overwrite Selection" under "Filter Options")
  177.  
  178.     perlPromptArgs         
  179.  
  180. (same as "Prompt For Args" under "General Options")
  181.  
  182.     perlUseDebug         
  183.  
  184. (same as "Use Debugger" under "General Options" ) 
  185.  
  186.     perlUsebuffer         
  187.  
  188. (same as "Apply To Buffer" under "Filter Options")
  189.  
  190.     perlRecycleOutput     
  191.  
  192. If selected, output returned by Macperl overwrites previous output in the
  193. "* Perl Output *" window in Alpha, instead of going into a new window.
  194.  
  195. There are also two additional preferences that may be examined:
  196.  
  197.     perlLastFilter        
  198.  
  199. Contains the location of the last text-filter script used.
  200.  
  201.     perlCmdlineArgs     
  202.  
  203. Contains the last command-line options supplied.
  204.  
  205. Note these are only passed to scripts when the "Prompt for Args" option is
  206. active.
  207.  
  208.  
  209.           MacPerl Menu
  210.  
  211.  
  212. Alpha's MacPerl menu allows a number of actions.  These are ...
  213.  
  214.                MacPerl interaction
  215.  
  216.  
  217.     Macperl                  
  218.  
  219. Switch to the MacPerl application.
  220.  
  221.  
  222.                Tell Macperl ...
  223.  
  224.     
  225.     Open In Macperl        
  226.  
  227. Open the current document in MacPerl.
  228.     
  229.     Save As Droplet        
  230.  
  231. Save the current document as a MacPerl droplet.
  232.     
  233.     Save As Droplet        
  234.  
  235. Save the current document as a MacPerl runtime script.
  236.     
  237.     Save As CGI            
  238.  
  239. Save the current document as a MacPerl CGI applet.
  240.     
  241. A bug in the AEGizmos package makes it impossible to create CGI applets
  242. directly from Alpha at this point.  You will have to open the script in
  243. MacPerl and save it from there.
  244.     
  245.     Open Output Window     
  246.  
  247. Retrieve the contents of MacPerl's main output window into a new window
  248. under Alpha.
  249.     
  250.     Close Output Window    
  251.  
  252. Close MacPerl's main output and debugger windows.
  253.     
  254.     Quit                  
  255.  
  256. Force the MacPerl application to quit. 
  257.  
  258.  
  259.  
  260.                Running Perl Scripts
  261.  
  262.  
  263.     Run The Selection      
  264.  
  265. Execute the selected text as a Perl script.
  266.  
  267.     Run The Buffer      
  268.  
  269. Execute the current text window as a Perl script.
  270.  
  271.     Save And Run          
  272.  
  273. Save the current window and run the saved file as a Perl script.  (see
  274. Current Directory)
  275.  
  276.     Run A File          
  277.  
  278. Run a selected disk file as a Perl script.  
  279.  
  280.                Applying Text Filter Scripts
  281.  
  282.  
  283.     Text Filters
  284.  
  285. A hierarchical menu of "preattached" scripts to use as text filters.  When
  286. a script is selected from this menu, it is immediately applied to the
  287. current text window.
  288.                 
  289. The menu is built from the contents of a user-selected folder.  The folder
  290. is chosen using the "Mode:App Paths" menu command on the main menubar or
  291. the "Text Filters Folder" command under the Macperl "Filter Options"
  292. submenu (below).
  293.                 
  294.     Select Buffer As Filter    
  295.  
  296. Select one of the open text windows to use as the text filter script.
  297.  
  298.     Select File As Filter    
  299.  
  300. Select a file to use as the text filter script.
  301.  
  302.     Repeat Last Filter        
  303.  
  304. Run again the last filter that was used.
  305.  
  306. If the contents of the file or buffer has changed, the new script is run.
  307.  
  308.  
  309.                Option flags
  310.  
  311.     
  312.     General Options
  313.     ---------------
  314.  
  315. Flags that control Alpha's behavior when executing ordinary scripts (not
  316. text filters).
  317.      
  318.     Retrieve Output        
  319.  
  320. Automatically retrieve any output written to the MacPerl output window and
  321. display it in a new window under Alpha.  (same as "perlGetOutput")
  322.  
  323. If the mode variable "perlRecycleOutput" is set, the previous output window
  324. is overwritten.
  325.                          
  326.     Auto Switch            
  327.  
  328. Switch to MacPerl while scripts are being executed.  Otherwise, Alpha
  329. remains frontmost until the script finishes.  (same as "perlAutoSwitch")
  330.  
  331.     Prompt For Args        
  332.  
  333. Have Alpha prompt you for command-line arguments to be passed to the
  334. script.  (same as "perlPromptArgs")
  335.  
  336.     Use Debugger         
  337.  
  338. Force the script to run under the MacPerl debugger.  (same as
  339. "perlUseDebug")
  340.      
  341. Control is automatically switched to MacPerl when the debugger is used.
  342.     
  343.  
  344.     Filter Options
  345.     --------------
  346.  
  347. Flags controlling the behavior of text filters mechanism.
  348.                      
  349.     Apply To Buffer        
  350.  
  351. Apply the filter to the entire current text window; otherwise, only the
  352. selected text is used.  (same as "perlUseBuffer")
  353.                          
  354.     Overwrite Selection    
  355.  
  356. When checked, the output from the text filter script will replace the input
  357. text in the original window.  Otherwise, the output is written into a new
  358. window.  (same as "perlOverwrite")
  359.  
  360.     Text Filters Folder  
  361.  
  362. Select the folder from which the Text Filters menu is built.  (You can also
  363. use the "Mode:App Paths" menu.)
  364.  
  365.     Rebuild Filter Menu  
  366.  
  367. Reconstruct the "Text Filters" menu from the contents of the designated
  368. "Text Filters" folder.
  369.         
  370.                         
  371.  
  372.           
  373.     ======================================================================
  374.  
  375.  
  376.           Running Scripts
  377.  
  378.  
  379. Running scripts using the MacPerl menu is pretty straightforward.  You can
  380. send the current selection, the entire current buffer, or a disk file to
  381. MacPerl for execution as a Perl script; the result will be the same as if
  382. you ran the script from MacPerl itself.  Here are listed some important
  383. points to remember when running Perl scripts using the MacPerl menu.
  384.  
  385.                Input and Output
  386.  
  387.  
  388. • Except for text filter scripts, the standard input for your script 
  389.   is taken from the keyboard (while MacPerl is in the foreground) and
  390.   standard output goes to MacPerl's output window.
  391.     
  392.   If you need to interact with the script while it's running, make sure
  393.   that you've selected the "AutoSwitch" flag under "General Options".
  394.  
  395. • To get the output from your script, select the "Retrieve Output" 
  396.   flag under "General Options", this will cause Alpha to copy any output to
  397.   Macperl's standard output window back into Alpha after your script has
  398.   completed.  You can always do this manually by using the "Get Output
  399.   Window" command under the "Tell Macperl…" submenu.
  400.     
  401.   Again, if you need to see the results while the script is running, use
  402.   AutoSwitch" to bring MacPerl to the foreground during script execution.
  403.  
  404.                Current Directory
  405.  
  406.  
  407. For the purpose of resolving relative file references, etc., within your
  408. script, it's important to understand how the current directory of the
  409. running script (as returned by `pwd` ) is determined.
  410.  
  411. • If you run a script file (using "Run A File"), then the folder containing
  412.   that file is the current folder.
  413.  
  414. • If you run a script from a text buffer (using "Run The Buffer" or "Run 
  415.   The Selection") , it is as though you ran it directly from a window in
  416.   the MacPerl application, and so the current directory your script sees
  417.   is the MacPerl application folder.
  418.     
  419. • If you run a script from a buffer using the "Save and Run" command, 
  420.   then the script is first saved to disk and then executed as a script
  421.   file.  In this case, the current directory is that of the script file.
  422.  
  423.  
  424.                Command-line Args
  425.  
  426.  
  427. • If the menu flag "Prompt For Args" is checked, then the user is prompted 
  428.   for command-line arguments at the time the script is run.  These will be 
  429.   available inside the script through the @ARGV array, as usual.  They are 
  430.   also saved in the Perl-mode variable "perlCmdlineArgs", and become the 
  431.   default arguments the next time the script is executed.
  432.  
  433.                Error Messages
  434.  
  435.  
  436. • If the script fails for some reason, Alpha will read the error messages 
  437.   returned by MacPerl and write them back into a new text window, called 
  438.   "* Perl Errors *".  
  439.  
  440. • The script that generated the error is brought up 
  441.   and the first line specifically referenced in an error message is 
  442.   highlighted.
  443.  
  444.   Note that error-trapping remains active whether "Retrieve Output" is set 
  445.   or not.
  446.  
  447.  
  448.                Interrupting a Script
  449.  
  450.  
  451. When you run a Perl script from Alpha, Alpha will display the watch cursor
  452. and wait for the reply from Macperl before doing anything else.  There may
  453. be times when this is inappropriate, for instance, if you expect the script
  454. to run for a long time or if you think the script is misbehaving for some
  455. reason.
  456.  
  457. • You can always tell Alpha to stop waiting for a script to finish by 
  458.   hitting "Cmd-.".  
  459.   
  460.   This does not abort the script itself; to do that you'll have to switch 
  461.   over to MacPerl to terminate the script there, as well.
  462.  
  463. • When you interrupt a script in this way, Alpha will no longer 
  464.   automatically get the output or error messages from MacPerl, when and if 
  465.   the script does finally terminate.
  466.   
  467.   You can always retrieve the contents of the output window yourself using 
  468.   "Get Output Window" from the "Tell MacPerl…" submenu or simply by 
  469.   switching over to Macperl itself.
  470.  
  471. There are some simple causes for a hung script.  For instance, if MacPerl
  472. is configured to check for "#!"  lines in scripts and yours doesn't have
  473. one, it will put up a dialog asking whether or not to procede.  If you
  474. didn't switch over to MacPerl when the script was run, you have know way of
  475. knowing this, and so you and Alpha may end up just sitting there waiting.
  476.  
  477.  
  478.           Text Filters
  479.  
  480.  
  481. Perl is, among other things, a powerful tool for extracting and rewriting
  482. data from text files.  On a Unix system, one would typically write
  483. text-processing scripts to read from "standard input" and write to
  484. "standard output", taking advantage of command-line i/o redirection to
  485. specify the actual input and output files used at any given time.  On the
  486. Mac, the typical absence of a command-line interface makes it harder to use
  487. this elegant method.
  488.  
  489. The MacPerl menu in Alpha makes it possible to use scripts that read from
  490. standard input and write to standard output to process text buffers in
  491. Alpha directly.  Any text window can be used as standard input and standard
  492. output can either be directed back to that same window or to a newly
  493. created one.  The script used may either be a disk file or yet another
  494. Alpha text window.
  495.  
  496.  
  497.                Applying a Text Filter 
  498.  
  499.  
  500. The procedure for using Perl text filters in Alpha is simple:
  501.  
  502. 1. Bring the text window you want to operate on to the front and select 
  503.    (highlight) the text that will be the input to the script.
  504.    
  505.  • If the "Apply To Buffer" option is selected, then the entire text 
  506.    window will be used as input and any text selection is ignored.
  507.    
  508.  • Only complete lines are used as input.  The text used will be extended 
  509.    to include all of the lines on which the selected text lies.
  510.  
  511. 2. Select a Perl script using one of the commands, "Select Buffer As 
  512.    Filter", "Select File As Filter" or "Repeat Last Filter" from the Perl 
  513.    menu, or by choosing one of the scripts listed in the "Text Filters" 
  514.    submenu.
  515.  
  516.  • You can see the name of the last script used by examining the 
  517.    variable "perlLastFilter" under the "√" menu in Perl mode. This
  518.    is the script that will be used if you use "Repeat Last Filter" 
  519.      
  520.  • If the "Prompt For Args" option has been selected, you'll be given 
  521.    a dialog box to type in the command-line arguments for the script. 
  522.  
  523. 3. The output of the script is written back out, either in the place of 
  524.    the input text (if the "Overwrite Selection" option is selected) or into 
  525.    a new text window.
  526.         
  527.  • As always, Alpha's unlimited undo capability let's you recover if you 
  528.    accidently overwrite the input text when you didn't want to.
  529.     
  530.  • If the script halts on an error, the filter operation is aborted 
  531.    and any error messages are displayed in a new window.
  532.  
  533.  
  534. The ability to take the script itself from a text window allows simple
  535. one-time scripts to be created and applied on the fly.  This can be very
  536. useful because, even with the overhead to start up MacPerl, large-scale
  537. global search-and-replace operations (hundreds of replaces) can be
  538. substantially faster in MacPerl than in Alpha.  Also, you might find it
  539. easier to apply a series of regular expression substitutions using a
  540. single, short Perl script, rather than a number of separate "Find" and
  541. "Replace All" commands in Alpha.
  542.  
  543.  
  544.                Preattached Scripts
  545.  
  546.  
  547. Frequently used text filter scripts can be conveniently accessed by placing
  548. them in a folder called "Text Filters" within the MacPerl application
  549. folder.  When the MacPerl menu is first created, it looks in this folder
  550. and builds a hierarchical submenu from the names of the scripts that it
  551. finds.  Note that it will also create a "Text Filters" folder if one
  552. doesn't already exist.
  553.  
  554. A sampling of useful :-) Perl scripts is distributed with Alpha in the
  555. folder ":Tcl:UserCode:Text Filters".
  556.  
  557. Of the scripts in the sample collection, the "Text Munging" scripts
  558. ("shuffle", "sort lines", "travesty", and "wordcount") were taken from the
  559. Camel book (Programming Perl).  The "s2p" script is my adaptation of the
  560. standard code that converts Unix "sed" scripts to Perl (it was modified to
  561. work without using the C preprocessor.)  "Strip Mail Headers" takes e-mail
  562. files and edits out any header lines but the few that I typically care
  563. about ("From:, "Date:", etc..).  "CC To BibTeX" is a script I use that
  564. takes listings from the online "Current Contents" database and rewrites
  565. them as BibTeX database entries.  To try it out, select (highlight) the
  566. sample Current Contents citation below and choose "CC To BibTeX" from the
  567. "Text Filters" submenu (make sure that "Apply To Buffer" is _not_ checked
  568. before you do!)
  569.  
  570. 288. VOS MH; LAMBRY JC; ROBLES SJ; YOUVAN DC; and others.
  571.        FEMTOSECOND SPECTRAL EVOLUTION OF THE EXCITED STATE OF BACTERIAL
  572.      REACTION CENTERS AT 10-K.
  573.        PROCEEDINGS OF THE NATIONAL ACADEMY OF SCIENCES OF THE UNITED STATES OF
  574.      AMERICA, 1992 JAN 15, V89 N2:613-617.
  575.  
  576.  
  577.           MacPerl application
  578.  
  579.  
  580. MacPerl was written (ported to the Mac) by
  581.  
  582.           Matthias Neeracher <neeri@iis.ee.ethz.ch>, and 
  583.           Tim Endres <time@ice.com>.
  584.  
  585. If you don't already have MacPerl, it's available by anonymous ftp 
  586.  
  587.   <ftp://ftp.switch.ch/software/mac/perl> ,  or
  588.   <ftp://ftp.share.com/pub/macperl>
  589.   
  590.  
  591. More information about MacPerl is available from the MacPerl Q&A page,
  592.  
  593.   <http://err.ethz.ch/members/neeri/macintosh/perl-qa.html> ,
  594.   
  595. Hal Wine's official MacPerl FAQ,
  596.  
  597.   <ftp://ftp.netcom.com/pub/ha/hal/MacPerl/>
  598.   
  599. and Sandra Silcott's MacPerl Primer, 
  600.  
  601.   <http://www.unimelb.edu.au/~ssilcot/macperl-primer/home.html>
  602.   
  603. which contains useful hints and sample scripts.
  604.        
  605.  
  606.           Bugs, etc.
  607.  
  608.  
  609. Comments and suggestions regarding this package are always welcome.  If
  610. there's something that bothers you, or some additional capability that
  611. you'd like to see, let me know and I'll see what I can do.
  612.  
  613. Bug reports and any other comments should be directed to
  614.  
  615. Author:       Tom Pollard    <pollard@chem.columbia.edu>
  616.  
  617. Contributors: Dan Herron     <herron@cogsci.ucsd.edu>
  618.               David Schooley <schooley@ee.gatech.edu>
  619.               Vince Darley   <vince@santafe.edu>
  620.               Martijn Koster <m.koster@nexor.co.uk>
  621.               Rob Calhoun    <rcalhoun@alum.mit.edu> 
  622.           
  623.     ======================================================================
  624.  
  625.  
  626.           Version History
  627.  
  628.  
  629. See the "perlVersionHistory.tcl" file for the latest changes.
  630.  
  631.  
  632.  
  633. Author: Tom Pollard 
  634. e-mail: <pollard@chem.columbia.edu>
  635.  
  636. MacPerl Help file updated by Craig Barton Upright
  637.  
  638. E-mail: <cupright@princeton.edu>
  639.   mail: Princeton University,  Department of Sociology
  640.         Princeton, New Jersey  08544
  641.    www: <http://www.princeton.edu/~cupright/>
  642.  
  643.